/*=============================================================================
#    The element-comm is a tentative program used to test our ideas.           
#                       Copyright (C)  bgao                                    
#
#     This program is free software; you can redistribute it and/or            
#      modify it under the terms of the GNU General Public License             
#     as published by the Free Software Foundation; either version 2           
#         of the License, or (at your option) any later version.               
#
#     This program is distributed in the hope that it will be useful,          
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            
#             GNU General Public License for more details.                    
#
#    You should have received a copy of the GNU General Public License        
#     along with this program; if not, write to the Free Software             
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,             
#                       MA  02110-1301, USA.                                  
#==============================================================================
# $Id: timer.h 348 2010-11-29 09:01:16Z bgao $ 
#
# $Author: bgao $ 
#
# $Revision: 348 $ 
#
# $Date: 2010-11-29 17:01:16 +0800 (星期一, 29 十一月 2010) $ 
#
# Description: 
#
=============================================================================*/
/*! @file timer.h
 *  @brief This file defines the interfaces for the timer used by MAC.
 */
#ifndef _TIMER_H_
#define _TIMER_H_

#include <math.h>
#include "common.h"
#include "sub_timer.h"

/*! number of micro-seconds per tick */
#define USEC_PER_TICK 1
/*! number of micro-seconds per symbol */
#define USEC_PER_SYMBOL 16
/*! number of symbols per tick */
#define SYMBOL_TO_TICK(n) (int)ceil((double)n * USEC_PER_SYMBOL / USEC_PER_TICK)

/*! the timer callback function type */
typedef void (*timer_callback)(int8 signum);

/*! the timer structure */
typedef struct mtimer_t_ {
    timer_callback func;
    uint32 expire;
    /* which should be defined in the sub_timer.h */
    struct sub_timer_t sub_timer;
    //uint8 index;
    //struct mtimer_t w_timer;
} mtimer_t;

int8 timer_init(mtimer_t *timer, timer_callback func);
int8 timer_start(mtimer_t *timer, uint16 expire);
int8 timer_stop(mtimer_t *timer);

int32 timer_get(void);

/* TODO should provide a timer which has a bigger resolusion */

#endif /* _TIMER_H_ */
